package org.apache.ignite.examples.model;

import org.apache.ignite.cache.query.annotations.QuerySqlField;

import java.io.Serializable;

/**
 * Created by xbkaishui on 16/8/7.
 */
public class Stock implements Serializable {

    @QuerySqlField(index = true)
    public String sCode;
    @QuerySqlField(index = true)
    public String marketType;
    @QuerySqlField(index = true)
    public int codeType;

    @QuerySqlField(index = true)
    public Double aTrade;

    public Double inc_vol, inc_amt;

    @QuerySqlField(index = true)
    public Double aOpen;
    public Double aHigh, aLow, aClose, yClose, preClose,isTrade;
    public String  tDate, mtime;
    public String timeStemp;
    @QuerySqlField(index = true)
    public String date;
    public String month;

    public Stock() {
    }

    public Stock(String sCode, String marketType, int codeType, Double aTrade, Double inc_vol, Double inc_amt, Double aOpen, Double aHigh, Double aLow, Double aClose, Double yClose, Double preClose, String tDate, String mtime, String timeStemp, String date, String month) {
        this.sCode = sCode;
        this.marketType = marketType;
        this.codeType = codeType;
        this.aTrade = aTrade;
        this.inc_vol = inc_vol;
        this.inc_amt = inc_amt;
        this.aOpen = aOpen;
        this.aHigh = aHigh;
        this.aLow = aLow;
        this.aClose = aClose;
        this.yClose = yClose;
        this.preClose = preClose;
        this.tDate = tDate;
        this.mtime = mtime;
        this.timeStemp = timeStemp;
        this.date = date;
        this.month = month;
    }

    public String getsCode() {
        return sCode;
    }

    public void setsCode(String sCode) {
        this.sCode = sCode;
    }

    public String getMarketType() {
        return marketType;
    }

    public void setMarketType(String marketType) {
        this.marketType = marketType;
    }

    public int getCodeType() {
        return codeType;
    }

    public void setCodeType(int codeType) {
        this.codeType = codeType;
    }

    public Double getaTrade() {
        return aTrade;
    }

    public void setaTrade(Double aTrade) {
        this.aTrade = aTrade;
    }

    public Double getInc_vol() {
        return inc_vol;
    }

    public void setInc_vol(Double inc_vol) {
        this.inc_vol = inc_vol;
    }

    public Double getInc_amt() {
        return inc_amt;
    }

    public void setInc_amt(Double inc_amt) {
        this.inc_amt = inc_amt;
    }

    public Double getaOpen() {
        return aOpen;
    }

    public void setaOpen(Double aOpen) {
        this.aOpen = aOpen;
    }

    public Double getaHigh() {
        return aHigh;
    }

    public void setaHigh(Double aHigh) {
        this.aHigh = aHigh;
    }

    public Double getaLow() {
        return aLow;
    }

    public void setaLow(Double aLow) {
        this.aLow = aLow;
    }

    public Double getaClose() {
        return aClose;
    }

    public void setaClose(Double aClose) {
        this.aClose = aClose;
    }

    public Double getyClose() {
        return yClose;
    }

    public void setyClose(Double yClose) {
        this.yClose = yClose;
    }

    public Double getPreClose() {
        return preClose;
    }

    public void setPreClose(Double preClose) {
        this.preClose = preClose;
    }

    public String gettDate() {
        return tDate;
    }

    public void settDate(String tDate) {
        this.tDate = tDate;
    }

    public String getMtime() {
        return mtime;
    }

    public void setMtime(String mtime) {
        this.mtime = mtime;
    }

    public String getTimeStemp() {
        return timeStemp;
    }

    public void setTimeStemp(String timeStemp) {
        this.timeStemp = timeStemp;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public static Stock parseStock(String line) {
        String data[] = line.split("\\|");
//        System.out.println(data.length);
        Stock st = new Stock();
        try {

            st.sCode = data[0];
            st.marketType = data[1];
            st.codeType = Integer.parseInt(data[2]);
            st.aTrade = Double.valueOf(data[3]);
            st.inc_vol = Double.valueOf(data[4]);
            st.inc_amt = Double.valueOf(data[5]);
            st.aOpen = Double.valueOf(data[6]);
            st.aHigh = Double.valueOf(data[7]);
            st.aLow = Double.valueOf(data[8]);
            st.aClose = Double.valueOf(data[9]);
            st.yClose = Double.valueOf(data[10]);

            if(data.length == 17 ) {
                st.preClose = 0.0;
                st.isTrade = Double.valueOf(data[11]);
                st.tDate = data[12];
                st.mtime = data[13];
                st.timeStemp = data[14];
                st.date = data[15];
                st.month = data[16];
            }else{
                st.preClose = Double.valueOf(data[11]);
                st.isTrade = Double.valueOf(data[12]);
                st.tDate = data[13];
                st.mtime = data[14];
                st.timeStemp = data[15];
                st.date = data[16];
                st.month = data[17];
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return st;
    }

    @Override
    public String toString() {
        return "Stock{" +
                "sCode='" + sCode + '\'' +
                ", marketType='" + marketType + '\'' +
                ", codeType=" + codeType +
                ", aTrade=" + aTrade +
                ", inc_vol=" + inc_vol +
                ", inc_amt=" + inc_amt +
                ", aOpen=" + aOpen +
                ", aHigh=" + aHigh +
                ", aLow=" + aLow +
                ", aClose=" + aClose +
                ", yClose=" + yClose +
                ", preClose=" + preClose +
                ", tDate='" + tDate + '\'' +
                ", mtime='" + mtime + '\'' +
                ", timeStemp='" + timeStemp + '\'' +
                ", date='" + date + '\'' +
                ", month='" + month + '\'' +
                '}';
    }

    public static void main(String args[]) {
        String data = "300371|2|13|29.62|849380|25168425.16|29.7|29.87|29.43|29.62|29.73|1|20160805|150337|20160805 15:03:48|2016|08";
        Stock st = parseStock(data);
        System.out.println(st);
        System.out.println(parseStock("000823|2|13|8.88|15000|133251.0|8.89|8.89|8.88|8.88|9.0|8.89|1|20160805|1448|20160805 14:47:39|2016|08"));
    }

}
